package cn.nfwx.tv.manager;

import android.content.Context;
import android.util.Log;

import java.util.HashMap;
import java.util.Map;

import cn.nfwx.tv.callback.ResponseListener;
import cn.nfwx.tv.conts.Constants;
import cn.nfwx.tv.okhttp.CustomOkHttpClient;
import cn.nfwx.tv.okhttp.UrlHelper;

/**
 * Created by dell on 2017/11/15.
 */

public class HotColomnManager {
    private static String list_mysubscription_url = Constants.test_url + "/nfwx-user/v1/subscription?";

    /**
     * 获取列表
     *
     * @param pageNo   请求页数
     * @param callBack 回调(response: 网络结果封装类, columns: 我的订阅列表数据模型数组)
     */
    public static String requestHotColumnList(Context context, int pageNo, int pageSize, ResponseListener callBack) {
        String request_tag = "requestHotColumnList";
        CustomOkHttpClient.cancleAll(request_tag);
        StringBuilder builder = new StringBuilder(Constants.base_video_url + "/api?");
        builder.append("action=listVideos");
        builder.append("&cid=all");
        builder.append("&details=1");
        builder.append("&page_no=").append(pageNo);
        builder.append("&page_size=").append(pageSize);
        builder.append("&sort=monhot asc");
        builder.append("&sort=created_time desc");
        builder.append("&type=video");
        builder.append("&uid=").append(Constants.NFWX_UID);
        builder.append("&referer=").append(Constants.base_video_url);
        CustomOkHttpClient.postObjectRequest(context, builder.toString(), request_tag, callBack);
        return request_tag;
    }

    public static void subscribe(Context context, String cid, String name, String token, ResponseListener<String> callBack) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("cid", cid);
        params.put("name", name);
        CustomOkHttpClient.postObjectRequestWithHeader(context, list_mysubscription_url, params, "requestMySubscriptionList", token, callBack);
    }

    public static String requestHotList(Context context, int pageNo, int pageSize, ResponseListener callBack) {
        String request_tag = "requestHotColumnList";
        StringBuilder builder = new StringBuilder(Constants.base_video_url + "/api?");
        builder.append("action=listVideos");
        builder.append("&cid=all");
        builder.append("&details=true");
        builder.append("&page_no=").append(pageNo);
        builder.append("&page_size=").append(pageSize);
        builder.append("&sort=monhot asc");
        builder.append("&sort=created_time desc");
        builder.append("&type=playlist");
        builder.append("&uid=").append(Constants.NFWX_UID);
        builder.append("&referer=").append(Constants.base_video_url);
        Log.d("url:", builder.toString());
        CustomOkHttpClient.postObjectRequest(context, builder.toString(), request_tag, callBack);
        return request_tag;
    }

    /**
     * 视频截图
     *
     * @param path
     */
    public static String getVideoImg(String path) {
        StringBuilder stringBuilder = new StringBuilder(Constants.base_video_url);
        stringBuilder.append(path);
        stringBuilder.append(".jpg?type=vod&thumbnail=thumbnail.jpg");
        return stringBuilder.toString();
    }

    /**
     * 热门视频
     */
    public static String requestIjkHotVideos(Context context, int pageNo, int pageSize, ResponseListener callBack) {
        String request_tag = "requestIjkHotVideos";
        String url = UrlHelper.getIjkHotVideosUrl(pageNo, pageSize);
        CustomOkHttpClient.getObjectRequest(context, url, request_tag, callBack);
        return request_tag;
    }
}
